var subsetsWithDup = function (nums) {
  // 对数组进行排序
  nums.sort((a, b) => a - b)
  const ans = [[]]
  const dfs = function (index, temp) {
    if (index === nums.length) {
      return
    }
    for (var i = index; i < nums.length; i++) {
      if(i>index&&nums[i]===nums[i-1]) {
        continue
      }
      temp.push(nums[i])
      ans.push([...temp])
      dfs(i + 1, [...temp])
      temp.pop()
    }
  }
  dfs(0, [])
  return ans
};
console.log(subsetsWithDup([4,4,4,1,4]));